package www.openteam.com.ui;

import android.app.DatePickerDialog;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.util.SortedList;
import android.text.format.Time;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;

import www.openteam.com.R;
import www.openteam.com.bean.CustomConditon;
import www.openteam.com.bean.CustomOrder;
import www.openteam.com.bean.CustomType;
import www.openteam.com.bean.DeliverGoods;
import www.openteam.com.bean.DetailGather;
import www.openteam.com.bean.FQCGoodsField;
import www.openteam.com.bean.FQCGoodsInspect;
import www.openteam.com.bean.FQCHalfGoodsInspect;
import www.openteam.com.bean.IPQCMsg00;
import www.openteam.com.bean.IPQCMsg01;
import www.openteam.com.bean.IQCMsg00;
import www.openteam.com.bean.OTBusiness;
import www.openteam.com.bean.OTPolicy;
import www.openteam.com.bean.OTPrdctnMngmnt;
import www.openteam.com.bean.OutFactoryMsg;
import www.openteam.com.bean.PackTypeInfo;
import www.openteam.com.bean.PbProductInfo;
import www.openteam.com.bean.ProOrder;
import www.openteam.com.bean.ProductInfo;
import www.openteam.com.bean.QualityCtrl;
import www.openteam.com.bean.QueryCondition;
import www.openteam.com.bean.QueryCustom;
import www.openteam.com.bean.RealTime;
import www.openteam.com.bean.SRCKPlanMsg;
import www.openteam.com.bean.SRCPoduMsg;
import www.openteam.com.bean.SomeCustomInfo;
import www.openteam.com.tool.ToastUtil;
import www.openteam.com.ui.business.BuildCustomOrderMainFragment;
import www.openteam.com.ui.business.BuildProductInfoFragment;
import www.openteam.com.ui.business.DeliverNoteFragment;
import www.openteam.com.ui.business.EditProductInfoFragment;
import www.openteam.com.ui.realtime.EvaluateFragment;
import www.openteam.com.ui.prdctnMngmnt.Stock_TakFragment;
import www.openteam.com.workorder.BaseWorkOrderFragment;
import www.openteam.com.workorder.ZZWorkOrderFragment;
import www.openteam.com.workorder.HZRB_WorkOrderFragment;
import www.openteam.com.ui.business.LoadingListFragment;
import www.openteam.com.ui.business.NewBuildFragment;
import www.openteam.com.ui.business.QryCstmChildInfoFragment;
import www.openteam.com.ui.business.QueryCustomInfoFragment;
import www.openteam.com.ui.business.QueryCustomOrderInfoFragment;
import www.openteam.com.ui.business.UpdateCustomInfoFragment;
import www.openteam.com.ui.business.UpdateProductInfoFragment;
import www.openteam.com.ui.business.other.SearchCustomFragment;
import www.openteam.com.ui.business.other.SearchCustomPMCFragment;
import www.openteam.com.ui.business.other.SearchFragment;
import www.openteam.com.ui.business.other.SearchPackTypeFragment;
import www.openteam.com.ui.policy.CustomOrderApprovalFragment;
import www.openteam.com.ui.policy.PayableApprovalFragment;
import www.openteam.com.ui.policy.PurchaseOrderApprovalFragment;
import www.openteam.com.ui.policy.ReceivablesApprovalFragment;
import www.openteam.com.ui.policy.SendRcvApprlFragment;
import www.openteam.com.ui.policy.other.CODetailedFragement;
import www.openteam.com.ui.policy.other.PODetailedFragement;
import www.openteam.com.ui.prdctnMngmnt.SRCKPoduEditFragment;
import www.openteam.com.ui.prdctnMngmnt.SendRCKSearchFragment;
import www.openteam.com.ui.prdctnMngmnt.SendRCheckFragment;
import www.openteam.com.ui.prdctnMngmnt.SendRcvFragment;
import www.openteam.com.ui.qualityCntrl.FQCFragment;
import www.openteam.com.ui.qualityCntrl.FQCSeaechFragment;
import www.openteam.com.ui.qualityCntrl.IPQC00Fragment;
import www.openteam.com.ui.qualityCntrl.IPQCFragment;
import www.openteam.com.ui.qualityCntrl.IQC00Fragment;
import www.openteam.com.ui.qualityCntrl.IQCFragment;
import www.openteam.com.ui.realtime.DeliverGoodFragment;
import www.openteam.com.ui.realtime.PrintFragment;
import www.openteam.com.ui.realtime.ProduceScheduleFragment;
import www.openteam.com.ui.realtime.StockFragment;
import www.openteam.com.ui.realtime.TakeGoodFragment;

public class DetailedActivity extends ActionBarActivity {
    private FragmentManager mFragmentManager = getSupportFragmentManager();
    FragmentTransaction localFragmentTransaction = this.mFragmentManager.beginTransaction();
    private ActionBar actionBar;
    private String title;    //ActionBar的标题
    private RealTime[] realTime;  //实时跟踪的枚举类
    private OTPolicy[] policy;   //快速决策的枚举类
    private OTBusiness[] business;  //电子商务的枚举类
    private OTPrdctnMngmnt[] prdctnMngmnts;//生产管理
    private QualityCtrl[] qualityCtrls;//品质管理
    private DetailGather detailGather; //三个枚举类的汇总类
    private List<DetailGather> mList;
    private int year;
    private int dayOfMonth;
    private int monthOfYear;
    private int syear;
    private int smonthOfYear;
    private int sdayOfMonth;
    private DeliverGoods.DataEntity deliverGoods;
    private List<DeliverGoods.DataEntity> aList;
    long startMilli;
    long endMilli;
    long currentMilli;
    private EditText ed_1;
    private EditText ed_2;
    private EditText ed_3;
    private EditText ed_4;
    private EditText ed_5;
    private String rdsno;
    private String custid;
    private QueryCondition queryCondition;
    private final String TAG = DetailedActivity.class.getSimpleName();
    private String code;
    private String cCode;
    DeliverGoodFragment deliverGoodFragment = new DeliverGoodFragment();
    TakeGoodFragment takeGoodFragment = new TakeGoodFragment();
    ProduceScheduleFragment produceScheduleFragment = new ProduceScheduleFragment();
    NewBuildFragment newBuildFragment = new NewBuildFragment();
    UpdateCustomInfoFragment updateCustomInfoFragment = new UpdateCustomInfoFragment();
    CustomOrderApprovalFragment customOrderApprovalFragment = new CustomOrderApprovalFragment();
    PurchaseOrderApprovalFragment purchaseOrderApprovalFragment = new PurchaseOrderApprovalFragment();
    SendRcvApprlFragment sendRcvApprlFragment = new SendRcvApprlFragment();
    QueryCustomInfoFragment editCustomInfoFragment = new QueryCustomInfoFragment();
    QryCstmChildInfoFragment qryCstmChildInfoFragment = new QryCstmChildInfoFragment();
    ReceivablesApprovalFragment receivableApprovalFragment = new ReceivablesApprovalFragment();
    EditProductInfoFragment editProductInfoFragment = new EditProductInfoFragment();
    BuildProductInfoFragment buildProductInfoFragment;
    UpdateProductInfoFragment updateProductInfoFragment;
    PayableApprovalFragment payableApprovalFragment = new PayableApprovalFragment();
    StockFragment stockFragment = new StockFragment();
    PrintFragment printFragment = new PrintFragment();
    EvaluateFragment evaluateFragment = new EvaluateFragment();
    QueryCustomOrderInfoFragment editCustomOrderInfoFragment = new QueryCustomOrderInfoFragment();
    DeliverNoteFragment deliverNoteFragment = new DeliverNoteFragment();
    LoadingListFragment loadingListFragment = new LoadingListFragment();
    SendRcvFragment sendRcvFragment = new SendRcvFragment();
    IQCFragment iqcFragment = new IQCFragment();
    IQC00Fragment iqc00Fragment = new IQC00Fragment();
    IPQCFragment ipqcFragment = new IPQCFragment();
    IPQC00Fragment ipqc00Fragment = new IPQC00Fragment();
    FQCFragment fqcFragment = new FQCFragment();
    FQCSeaechFragment fqcSeaechFragment = new FQCSeaechFragment();
    SearchFragment searchFragment;
    SearchPackTypeFragment searchPackTypeFragment;
    SearchCustomFragment searchCustomFragment;
    SearchCustomPMCFragment searchCustomPMCFragment;
    ZZWorkOrderFragment ZZWorkOrderFragment = new ZZWorkOrderFragment();
    HZRB_WorkOrderFragment hzrb_workOrderFragment = new HZRB_WorkOrderFragment();
    BaseWorkOrderFragment baseWorkOrderFragment = new BaseWorkOrderFragment();
    SendRCheckFragment sendRCheckFragment = new SendRCheckFragment();
    SendRCKSearchFragment sendRCKSearchFragment;
    SRCKPoduEditFragment srckPoduEditFragment;
    Stock_TakFragment stock_takFragment = new Stock_TakFragment();
    BlankFragment blankFragment = new BlankFragment();
    private SearchFragmentButton searchFragmentButton;
    private SearchNewFragmentButton searchNewFragmentButton;
    private BuildCustomOrderMainFragment buildCustomOrderMainFragment
            = new BuildCustomOrderMainFragment();
    private CODetailedFragement cODetailedFragment;
    private static final String STATE_SAVE_IS_HIDDEN = "STATE_SAVE_IS_HIDDEN";
    private PODetailedFragement pODetailedFragment;
//    public static String FACTORY = "E_HZ_RB";
    public static String FACTORY = "ZZ";
//    public static String FACTORY = "BASE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detailed);
        Bundle bundle = this.getIntent().getExtras();
        //接收title值
        title = bundle.getString("title"); //接收上个页面点击的
        initView(); //初始化页面

        initData(); //初始化数据
        initCalendar();
        checkAthority();

        selectArray(title);
        if (savedInstanceState == null) {

            Log.e(TAG, "detailGather.getI(): " + detailGather.getI());
            switch (detailGather.getI()) {

                case 0:
                    //客户订单审批
                    addFragmentContent(customOrderApprovalFragment, "customOrderApprovalFragment");
                    break;
                case 1:
                    //采购订单审批
                    addFragmentContent(purchaseOrderApprovalFragment, "purchaseOrderApprovalFragment");
                    break;
                case 2:
                    //应收款审批
                    addFragmentContent(receivableApprovalFragment, "receivableApprovalFragment");
                    break;
                case 3:
                    //应付款审批
                    addFragmentContent(payableApprovalFragment, "payableApprovalFragment");
                    break;
                case 4:
                    // 发外工程单审批
                    addFragmentContent(sendRcvApprlFragment, "sendRcvApprlFragment");
                    break;
                case 5:
                    //编辑客户信息
                    addFragmentContent(editCustomInfoFragment, "editCustomInfoFragment");
                    break;
                case 6:
                    //编辑产品信息
                    addFragmentContent(editProductInfoFragment, "editProductInfoFragment");
                    break;
                case 7:
                    //编辑客户订单
                    addFragmentContent(editCustomOrderInfoFragment, "editCustomOrderInfoFragment");
                    break;
                case 8:
                    //送货单
                    addFragmentContent(deliverNoteFragment, "deliverNoteFragment");
                    break;
                case 9:
                    //装车清单

//                    addFragmentContent(blankFragment, "blankFragment");
                    addFragmentContent(loadingListFragment, "loadingListFragment");//loadingListFragment
                    break;
                case 10:
                    //采购进度
                    addFragmentContent(deliverGoodFragment, "deliverGoodFragment"); //添加Fragment
                    break;
                case 11:
                    //送货进度
                    addFragmentContent(takeGoodFragment, "takeGoodFragment");
                    break;
                case 12:
                    //生产进度
                    addFragmentContent(produceScheduleFragment, "produceScheduleFragment");
                    break;
                case 13:
//                    库存查询
                    addFragmentContent(stockFragment, "stockFragment");
                    break;
                case 14:
                    //印刷估价
//                    addFragmentContent(printFragment, "printFragment");
                    addFragmentContent(evaluateFragment, "evaluateFragment");
                    break;
                case 15:
                    //数据采集
                    addFragmentContent(ZZWorkOrderFragment, "ZZWorkOrderFragment");
//                    addFragmentContent(hzrb_workOrderFragment, "hzrb_workOrderFragment");
//                    addFragmentContent(baseWorkOrderFragment, "baseWorkOrderFragment");
                    break;
                case 16:
                    //发外收货
                    addFragmentContent(sendRcvFragment, "sendRcvFragment");

                    break;
                case 17:
                    //库存盘点
                    addFragmentContent(stock_takFragment, "stock_takFragment");

                    break;
//                case 17:
//                    //
//                    addFragmentContent(sendRCheckFragment, "sendRCheckFragment");
//                    break;
                case 18:
                    addFragmentContent(iqcFragment, "iqcFragment");
                    break;
                case 19:
                    addFragmentContent(ipqcFragment, "ipqcFragment");
                    break;
                case 20:
                    addFragmentContent(fqcFragment, "fqcFragment");
                    break;
                default:
                    BlankFragment blankFragment = new BlankFragment();
                    addFragmentContent(blankFragment, "blankFragment");
            }
            buttonClickEvent();
        }


    }

    private boolean checkAthority() {

        if (!detailGather.getAppAuthority().equals(null)) {
            Log.d(TAG, "checkAthority: " + detailGather.getAppAuthority());

        }

        return true;
    }


    /**
     * 初始化View
     */
    private void initView() {

        actionBar = getSupportActionBar();
        // 设置显示标题
        actionBar.setTitle(title);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        ed_1 = (EditText) findViewById(R.id.ed_1);
        ed_2 = (EditText) findViewById(R.id.ed_2);
        ed_3 = (EditText) findViewById(R.id.ed_3);
        ed_4 = (EditText) findViewById(R.id.ed_4);
    }


    public static String getIpAddress() {
        try {
            for (Enumeration<NetworkInterface> enNetI = NetworkInterface.getNetworkInterfaces(); enNetI
                    .hasMoreElements(); ) {
                NetworkInterface netI = enNetI.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = netI.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
                        return inetAddress.getHostAddress();
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        return "";
    }

    private void initData() {
        Log.e(TAG, "initData: " + FACTORY);
        policy = OTPolicy.values();
        business = OTBusiness.values();
        realTime = RealTime.values();//获取枚举的值
        prdctnMngmnts = OTPrdctnMngmnt.values();
        qualityCtrls = QualityCtrl.values();

        mList = new ArrayList<DetailGather>(); //初始化List
        for (int i = 0; i < policy.length + business.length + realTime.length + prdctnMngmnts.length + qualityCtrls.length; i++) {
            if (i >= 0 && i < policy.length) {
                detailGather = new DetailGather(i, policy[i].getResName(), policy[i].getResIcon(),
                        policy[i].getResDetail(), policy[i].getAppAuthority());
            }
            if (i >= policy.length && i < business.length + policy.length) {
                int tem = i - policy.length;
                detailGather = new DetailGather(i, business[tem].getResName(), business[tem].getResIcon(), business[tem].getResDetail(), null);
            }
            if (i >= business.length + policy.length && i < policy.length + business.length + realTime.length) {
                int tem = i - policy.length - business.length;
                detailGather = new DetailGather(i, realTime[tem].getResName(), realTime[tem].getResIcon(), realTime[tem].getResDetail(), realTime[tem].getAppAuthority());
            }
            if (i >= business.length + policy.length + realTime.length && i < policy.length + business.length + realTime.length + prdctnMngmnts.length) {
                int tem = i - policy.length - business.length - realTime.length;
                detailGather = new DetailGather(i, prdctnMngmnts[tem].getResName(), prdctnMngmnts[tem].getResIcon(), prdctnMngmnts[tem].getResDetail(), prdctnMngmnts[tem].getAppAuthority());
            }
            if (i >= business.length + policy.length + realTime.length + prdctnMngmnts.length && i < policy.length + business.length + realTime.length + prdctnMngmnts.length + qualityCtrls.length) {
                int tem = i - policy.length - business.length - realTime.length - prdctnMngmnts.length;
                detailGather = new DetailGather(i, qualityCtrls[tem].getResName(), qualityCtrls[tem].getResIcon(), qualityCtrls[tem].getResDetail(), qualityCtrls[tem].getAppAuthority());
            }
//            Log.d("aaa",getString(detailGather.getResName()));
            mList.add(detailGather); //把需要的枚举都加入List

        }


    }


    private void selectArray(String title) {
        for (DetailGather mdetailGather : mList) {
            if (title.equals(getString(mdetailGather.getResName()))) {
                Log.e(TAG, "selectArray: " + mdetailGather.getResName());
                this.detailGather = mdetailGather;
            }
        }
    }

    /**
     * 控制fragment的显示与隐藏
     *
     * @param showFragmentName   需要显示的Fragment
     * @param removeFragmentName 需要移除的Fragment
     */
    private void TheFragmentChange(String showFragmentName, String removeFragmentName
            , Fragment showFragment, Fragment removeFragment) {
        if (this.mFragmentManager.findFragmentByTag(showFragmentName) != null &&
                this.mFragmentManager.findFragmentByTag(removeFragmentName) != null) {
            if (this.mFragmentManager.findFragmentByTag(showFragmentName).isHidden() &&
                    !this.mFragmentManager.findFragmentByTag(removeFragmentName).isHidden()
                    ) {
                localFragmentTransaction = this.mFragmentManager.beginTransaction();
                localFragmentTransaction.show(showFragment)
                        .remove(removeFragment).hide(removeFragment);
//                Log.d(TAG, "TheFragmentChange:cs "+removeFragment.isRemoving());
//                Log.d(TAG, "TheFragmentChange:cs "+removeFragment.isHidden());
//                localFragmentTransaction.hide(removeFragment).replace(R.id.fragment_container,showFragment,showFragmentName).commitNow();
//                localFragmentTransaction.show(showFragment).commitNow();
                localFragmentTransaction.commitAllowingStateLoss();

                removeFragment = null;
            } else {

                this.finish();
            }
        } else {
            this.finish();
        }
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
//            if (newBuildFragment != null) {
//                TheFragmentChange("editCustomInfoFragment", "newBuildFragment",
//                        editCustomInfoFragment, newBuildFragment);
//            } else if (updateCustomInfoFragment != null) {
//                TheFragmentChange("editCustomInfoFragment", "updateCustomInfoFragment",
//                        editCustomInfoFragment, updateCustomInfoFragment);
//            } else if (buildProductInfoFragment != null) {
//                TheFragmentChange("editProductInfoFragment", "buildProductFragment",
//                        editProductInfoFragment, buildProductInfoFragment);
//            } else if (updateProductInfoFragment != null) {
//                TheFragmentChange("editProductInfoFragment", "updateProductInfoFragment",
//                        editProductInfoFragment, updateProductInfoFragment);
//            } else if (searchFragment != null) {
//                TheFragmentChange("editCustomOrderInfoFragment", "searchFragment",
//                        editCustomOrderInfoFragment, searchFragment);
//            } else if (cODetailedFragment != null) {
//                TheFragmentChange("customOrderApprovalFragment", "cODetailedFragment"
//                        , customOrderApprovalFragment, cODetailedFragment);
//            } else if (pODetailedFragment != null) {
//                TheFragmentChange("purchaseOrderApprovalFragment", "pODetailedFragment",
//                        purchaseOrderApprovalFragment, pODetailedFragment
//                );
//            } else {

//            this.finish();
//            }


            if (mFragmentManager.getBackStackEntryCount() > 1) {

                mFragmentManager.popBackStack();

                Log.d(TAG, "onKeyDown: " + mFragmentManager.getBackStackEntryCount());
            } else {
                this.finish();
            }
            Log.d(TAG, "onKeyDown: " + mFragmentManager.getBackStackEntryCount());
            return false;
        } else {
            return super.onKeyDown(keyCode, event);
        }

    }


    public DetailGather getDetailGather() {
        return detailGather;
    }


    public String getQueryCode() {
        return cCode;
    }


    public QueryCondition getQueryConditionT() {
        ed_1 = (EditText) findViewById(R.id.ed_1);
        ed_2 = (EditText) findViewById(R.id.ed_2);
        rdsno = ed_1.getText().toString();
        code = ed_2.getText().toString();
        queryCondition = new QueryCondition(rdsno, code);

        return queryCondition;
    }

    private void buttonClickEvent() {

        editCustomOrderInfoFragment.setOnClickJump(new QueryCustomOrderInfoFragment.OnClickJump() {
            @Override
            public void jumpToChild(CustomOrder.DataEntity dataEntity, boolean isInspect) {
                qryCstmChildInfoFragment.getdata(dataEntity, isInspect);
                replaceFragmentContent(qryCstmChildInfoFragment, "qryCstmChildInfoFragment");
            }
        });

        qryCstmChildInfoFragment.setChildButtton(new QryCstmChildInfoFragment.IChildButtton() {
            @Override
            public void onclickSearch(int mark, int position) {
                title = "搜索产品信息";
                actionBar.setTitle(title);
                searchFragment = new SearchFragment();
                switchContent(qryCstmChildInfoFragment, searchFragment, "searchFragment",
                        mark, position);
                searchFragment.buttonSetOnclick(new SearchFragment.ButtonSelect() {
                    @Override
                    public void buttonOnclickSelect(PbProductInfo.DataEntity pbProductInfo) {
                        code = "change";
                        searchFragmentButton.searchFramentButtonClick(pbProductInfo, code);
                        TheFragmentChange("qryCstmChildInfoFragment", "searchFragment",
                                qryCstmChildInfoFragment, searchFragment);

                    }
                });
            }

            @Override
            public void onclickSearchPackType() {
                title = "搜索包装方式";
                actionBar.setTitle(title);
                searchPackTypeFragment = new SearchPackTypeFragment();
                switchContent(qryCstmChildInfoFragment, searchPackTypeFragment,
                        "searchPackTypeFragment", 0, 0);
                searchPackTypeFragment.buttonSetOnclick(new SearchPackTypeFragment.ButtonSelect() {
                    @Override
                    public void buttonOnclickSelect(PackTypeInfo.DataEntity packTypeInfo) {
                        code = "change";
                        searchFragmentButton.searchPackTypeInfoClick(packTypeInfo, code);
                        TheFragmentChange("qryCstmChildInfoFragment", "searchPackTypeFragment",
                                qryCstmChildInfoFragment, searchPackTypeFragment);
                    }

                });
            }

        });

        editCustomOrderInfoFragment.buttonSetOnclick(
                new QueryCustomOrderInfoFragment.ButtonInterface() {
                    @Override
                    public void onclickSearch(int mark, int position) {
                        title = "搜索产品信息";
                        actionBar.setTitle(title);
                        searchFragment = new SearchFragment();
                        switchContent(editCustomOrderInfoFragment, searchFragment, "searchFragment",
                                mark, position);
                        searchFragment.buttonSetOnclick(new SearchFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(PbProductInfo.DataEntity pbProductInfo) {

                                code = "change";
                                searchFragmentButton.searchFramentButtonClick(pbProductInfo, code);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchFragment",
                                        editCustomOrderInfoFragment, searchFragment);

                            }
                        });
                    }

                    @Override
                    public void onClickNewBuild() {
                        title = "新建信息";
                        actionBar.setTitle(title);
                        switchContent(editCustomOrderInfoFragment, buildCustomOrderMainFragment,
                                "buildCustomOrderMainFragment",
                                0, 0);
                    }

                    @Override
                    public void onclickSearchPackType() {
                        title = "搜索产品信息";
                        actionBar.setTitle(title);
                        searchPackTypeFragment = new SearchPackTypeFragment();
                        switchContent(editCustomOrderInfoFragment, searchPackTypeFragment,
                                "searchPackTypeFragment", 0, 0);
                        searchPackTypeFragment.buttonSetOnclick(new SearchPackTypeFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(PackTypeInfo.DataEntity packTypeInfo) {
                                code = "change";
                                searchFragmentButton.searchPackTypeInfoClick(packTypeInfo, code);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchPackTypeFragment",
                                        editCustomOrderInfoFragment, searchPackTypeFragment);
                            }

                        });
                    }

                    @Override
                    public void onclickSearchCustom() {
                        title = "客户信息";
                        actionBar.setTitle(title);
                        searchCustomFragment = new SearchCustomFragment();
                        switchContent(editCustomOrderInfoFragment, searchCustomFragment,
                                "searchCustomFragment", 0, 0);
                        searchCustomFragment.buttonSetOnclick(new SearchCustomFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(SomeCustomInfo.DataEntity dataEntity) {
                                code = "change";
                                searchFragmentButton.searchCustomInfoClick(dataEntity);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchCustomFragment",
                                        editCustomOrderInfoFragment, searchCustomFragment);
                            }

                        });
                    }

                    @Override
                    public void onclickSearchMoneyName() {
                        title = "币别信息";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(0);
                        switchContent(editCustomOrderInfoFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchFragmentButton.searchComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchCustomPMCFragment",
                                        editCustomOrderInfoFragment, searchCustomPMCFragment);
                            }


                        });
                    }

                    @Override
                    public void onclickSearchCopayName() {
                        title = "支付类别";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(1);
                        switchContent(editCustomOrderInfoFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {

                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchFragmentButton.searchComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchCustomPMCFragment",
                                        editCustomOrderInfoFragment, searchCustomPMCFragment);
                            }


                        });
                    }

                    @Override
                    public void onclickSearchStypeName() {
                        title = "用户类别";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(2);
                        switchContent(editCustomOrderInfoFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {

                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchFragmentButton.searchComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchCustomPMCFragment",
                                        editCustomOrderInfoFragment, searchCustomPMCFragment);
                            }


                        });
                    }

                    @Override
                    public void onclickSearchSendName() {
                        title = "送货方式";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(3);
                        switchContent(editCustomOrderInfoFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {

                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchFragmentButton.searchComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("editCustomOrderInfoFragment", "searchCustomPMCFragment",
                                        editCustomOrderInfoFragment, searchCustomPMCFragment);
                            }


                        });
                    }
                });

        editProductInfoFragment.buttonSetOnclick(new EditProductInfoFragment.ButtonInterface() {
            @Override
            public void onclick(ArrayList<CustomType.DataBean> materialType) {
                title = "新建产品信息";
                actionBar.setTitle(title);
                buildProductInfoFragment = new BuildProductInfoFragment();
                switchContent(editProductInfoFragment, buildProductInfoFragment,
                        "buildProductFragment"
                        , null, null, materialType, null, null, 0);
                buildProductInfoFragment.buttonSetOnclick(new BuildProductInfoFragment.ButtonReturn() {
                    @Override
                    public void clickReturn(String code) {
                        Log.d(TAG, "clickReturn: jg");
                        TheFragmentChange("editProductInfoFragment", "buildProductFragment",
                                editProductInfoFragment, buildProductInfoFragment);
                        if (code != null) {
                            cCode = code;
                        }
                    }
                });
                cCode = null;
            }

            @Override
            public void clickUpdate(ArrayList<CustomType.DataBean> materialType, ProductInfo.DataEntity prod, int position) {
                title = "更新产品信息";
                actionBar.setTitle(title);
                Log.d(TAG, "clickUpdate: jg");
                updateProductInfoFragment = new UpdateProductInfoFragment();
                switchContent(editProductInfoFragment, updateProductInfoFragment,
                        "updateProductInfoFragment"
                        , prod, null, materialType, null, null, position);
                updateProductInfoFragment.buttonSetOnclick(new UpdateProductInfoFragment.ButtonReturn() {
                    @Override
                    public void clickReturn(String code) {
                        TheFragmentChange("editProductInfoFragment", "updateProductInfoFragment",
                                editProductInfoFragment, updateProductInfoFragment);
                        if (code != null) {
                            cCode = code;
                        }
                    }
                });
            }
        });

        editCustomInfoFragment.buttonSetOnclick(new QueryCustomInfoFragment.
                ButtonInterface() {
            @Override
            public void onclick(View view, int position, QueryCustom.DataBean queryCustom,
                                ArrayList<CustomConditon> customConditons,
                                ArrayList<CustomType.DataBean> customTypes, ArrayList<CustomType.DataBean> moneyTypes, ArrayList<CustomType.DataBean> copayTypes) {
                title = "新建客户信息  ";
                actionBar.setTitle(title);
                newBuildFragment = new NewBuildFragment();
                switchContent(editCustomInfoFragment, newBuildFragment, "newBuildFragment", queryCustom, customConditons, customTypes, moneyTypes, copayTypes, position);
                newBuildFragment.buttonSetOnclick(new NewBuildFragment.ButtonReturn() {
                    @Override
                    public void clickReturn(String code) {
                        TheFragmentChange("editCustomInfoFragment", "newBuildFragment",
                                editCustomInfoFragment, newBuildFragment);
                        if (code != null) {
                            cCode = code;
                        }
                    }
                });

            }


            @Override
            public void modify(View view, int position, QueryCustom.DataBean queryCustom, ArrayList<CustomConditon> customConditons, ArrayList<CustomType.DataBean> customTypes, ArrayList<CustomType.DataBean> moneyTypes, ArrayList<CustomType.DataBean> copayTypes, SortedList<QueryCustom.DataBean> mSortedList) {
                title = "更新客户信息";
                actionBar.setTitle(title);
//                updateCustomInfoFragment = new UpdateCustomInfoFragment();
                switchContent(editCustomInfoFragment, updateCustomInfoFragment, "updateCustomInfoFragment"
                        , queryCustom, customConditons, customTypes, moneyTypes, copayTypes, position);
                updateCustomInfoFragment.buttonSetOnclick(new UpdateCustomInfoFragment.ButtonReturn() {
                    @Override
                    public void clickReturn(String code) {
                        TheFragmentChange("editCustomInfoFragment", "updateCustomInfoFragment",
                                editCustomInfoFragment, updateCustomInfoFragment);
                        if (code != null) {
                            cCode = code;
                        }
                    }
                });

            }


        });

//        customOrderApprovalFragment.vhOnClickInt(
//                new CustomOrderApprovalFragment.vHOnClickInt() {
//                    @Override
//                    public void dOnclick(OrderApproval.DataEntity orderApproval) {
//
//                        cODetailedFragment = new CODetailedFragement();
//                        title = "订单详细信息";
//                        actionBar.setTitle(title);
//                        Log.d(TAG, "dOnclick: cs");
//                        switchContent(customOrderApprovalFragment, cODetailedFragment,
//                                "cODetailedFragment",
//                                orderApproval, null, null, null, null, 0);
//                    }
//                });

        purchaseOrderApprovalFragment.vhOnClickInt(new PurchaseOrderApprovalFragment.vHOnClickInt() {
            @Override
            public void dOnclick(ProOrder.DataEntity proOrder) {
                pODetailedFragment = new PODetailedFragement();
                title = "采购单详细信息";
                actionBar.setTitle(title);
                Log.d(TAG, "dOnclick: cs");
                switchContent(purchaseOrderApprovalFragment, pODetailedFragment,
                        "pODetailedFragment",
                        proOrder, null, null, null, null, 0);
            }
        });

        buildCustomOrderMainFragment.buttonSetOnclick(
                new BuildCustomOrderMainFragment.ButtonInterface() {
                    @Override
                    public void onclickSearch() {
                        title = "搜索产品信息";
                        actionBar.setTitle(title);
                        searchFragment = new SearchFragment();
                        switchContent(buildCustomOrderMainFragment,
                                searchFragment, "searchFragment",
                                0, 0);
                        searchFragment.buttonSetOnclick(new SearchFragment.ButtonSelect() {

                            @Override
                            public void buttonOnclickSelect(PbProductInfo.DataEntity pbProductInfo) {
                                code = "change";
                                searchNewFragmentButton.searchNewFramentButtonClick(pbProductInfo, code);
                                TheFragmentChange("buildCustomOrderMainFragment", "searchFragment",
                                        buildCustomOrderMainFragment, searchFragment);
                            }
                        });
                    }

                    @Override
                    public void onClickNewBuild() {
                        title = "新建信息";
                        actionBar.setTitle(title);
                        switchContent(buildCustomOrderMainFragment, buildCustomOrderMainFragment,
                                "buildCustomOrderMainFragment",
                                0, 0);
                    }

                    @Override
                    public void insertSucces() {
//                        switchContent(editCustomOrderInfoFragment,buildCustomOrderMainFragment,
//                                "buildCustomOrderMainFragment",
//                                0,0);

                        TheFragmentChange(
                                "editCustomOrderInfoFragment", "buildCustomOrderMainFragment",
                                editCustomOrderInfoFragment, buildCustomOrderMainFragment
                        );
                    }

                    @Override
                    public void onclickSearchPackType() {
                        title = "搜索产品信息";
                        actionBar.setTitle(title);
                        searchPackTypeFragment = new SearchPackTypeFragment();
                        switchContent(buildCustomOrderMainFragment, searchPackTypeFragment,
                                "searchPackTypeFragment", 0, 0);
                        searchPackTypeFragment.buttonSetOnclick(new SearchPackTypeFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(PackTypeInfo.DataEntity packTypeInfo) {
                                code = "change";
                                searchNewFragmentButton.searchNewPackTypeInfoClick(packTypeInfo, code);
                                TheFragmentChange("buildCustomOrderMainFragment", "searchPackTypeFragment",
                                        buildCustomOrderMainFragment, searchPackTypeFragment);
                            }
                        });
                    }

                    @Override
                    public void onclickSearchCustom() {
                        title = "客户信息";
                        actionBar.setTitle(title);
                        searchCustomFragment = new SearchCustomFragment();
                        switchContent(buildCustomOrderMainFragment, searchCustomFragment,
                                "searchCustomFragment", 0, 0);
                        searchCustomFragment.buttonSetOnclick(new SearchCustomFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(SomeCustomInfo.DataEntity dataEntity) {
                                code = "change";
                                searchNewFragmentButton.searchNewCustomInfoClick(dataEntity);
                                TheFragmentChange("buildCustomOrderMainFragment", "searchCustomFragment",
                                        buildCustomOrderMainFragment, searchCustomFragment);
                            }

                        });
                    }


                    @Override
                    public void onclickSearchMoneyName() {
                        title = "币别信息";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(0);
                        switchContent(buildCustomOrderMainFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {
                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchNewFragmentButton.searchNewComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("buildCustomOrderMainFragment", "searchCustomPMCFragment",
                                        buildCustomOrderMainFragment, searchCustomPMCFragment);
                            }


                        });
                    }


                    @Override
                    public void onclickSearchCopay() {
                        title = "支付类别";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(1);
                        switchContent(buildCustomOrderMainFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {

                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchNewFragmentButton.searchNewComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("buildCustomOrderMainFragment", "searchCustomPMCFragment",
                                        buildCustomOrderMainFragment, searchCustomPMCFragment);
                            }


                        });
                    }

                    @Override
                    public void onclickSearchSendName() {
                        title = "送货方式";
                        actionBar.setTitle(title);
                        searchCustomPMCFragment = new SearchCustomPMCFragment(3);
                        switchContent(buildCustomOrderMainFragment, searchCustomPMCFragment,
                                "searchCustomPMCFragment", 0, 0);
                        searchCustomPMCFragment.buttonSetOnclick(new SearchCustomPMCFragment.ButtonSelect() {

                            @Override
                            public void buttonOnclickSelect(CustomType.DataBean dataBean, int type) {
                                code = "change";
                                searchNewFragmentButton.searchNewComtomTypeInfoClick(dataBean, type);
                                TheFragmentChange("buildCustomOrderMainFragment", "searchCustomPMCFragment",
                                        buildCustomOrderMainFragment, searchCustomPMCFragment);
                            }


                        });
                    }
                });

        editProductInfoFragment.buttonSetOnclick(new EditProductInfoFragment.ButtonInterface() {
            @Override
            public void onclick(ArrayList<CustomType.DataBean> materialType) {
                title = "新建产品信息";
                actionBar.setTitle(title);
                buildProductInfoFragment = new BuildProductInfoFragment();
                switchContent(editProductInfoFragment, buildProductInfoFragment,
                        "buildProductFragment"
                        , null, null, materialType, null, null, 0);
                buildProductInfoFragment.buttonSetOnclick(new BuildProductInfoFragment.ButtonReturn() {
                    @Override
                    public void clickReturn(String code) {
                        Log.d(TAG, "clickReturn: jg");
                        TheFragmentChange("editProductInfoFragment", "buildProductFragment",
                                editProductInfoFragment, buildProductInfoFragment);
                        if (code != null) {
                            cCode = code;
                        }
                    }
                });
                cCode = null;
            }

            @Override
            public void clickUpdate(ArrayList<CustomType.DataBean> materialType, ProductInfo.DataEntity prod, int position) {
                title = "更新产品信息";
                actionBar.setTitle(title);
                Log.d(TAG, "clickUpdate: jg");
                updateProductInfoFragment = new UpdateProductInfoFragment();
                switchContent(editProductInfoFragment, updateProductInfoFragment, "updateProductInfoFragment"
                        , prod, null, materialType, null, null, position);
                updateProductInfoFragment.buttonSetOnclick(new UpdateProductInfoFragment.ButtonReturn() {
                    @Override
                    public void clickReturn(String code) {
                        TheFragmentChange("editProductInfoFragment", "updateProductInfoFragment",
                                editProductInfoFragment, updateProductInfoFragment);
                        if (code != null) {
                            cCode = code;
                        }
                    }
                });
            }
        });

        ipqcFragment.setJumpData(new IPQCFragment.JumpData() {
            @Override
            public void onclickListener00(IPQCMsg00.DataBeanX.DataBean dataBean) {
                ipqc00Fragment.getdata00(dataBean);
                replaceFragmentContent(ipqc00Fragment, "ipqc00Fragment");
            }

            @Override
            public void onclickListener01(IPQCMsg01.DataBeanX.DataBean dataBean) {
                ipqc00Fragment.getdata01(dataBean);
                replaceFragmentContent(ipqc00Fragment, "ipqc00Fragment");
            }

        });

        iqcFragment.setCallBack(new IQCFragment.CallBack() {
            @Override
            public void putData00(IQCMsg00.DataBeanX.DataBean dataBean) {
                iqc00Fragment.getData00(dataBean);
                replaceFragmentContent(iqc00Fragment, "iqc00Fragment");
            }

            @Override
            public void putData01() {

            }
        });


        fqcFragment.setiSearch(new FQCFragment.ISearch() {
            @Override
            public void goodsYeild(FQCGoodsField fqcGoodsField) {
                fqcSeaechFragment.onGoodsField(fqcGoodsField);
                replaceFragmentContent(fqcSeaechFragment, "fqcSeaechFragment");
            }

            @Override
            public void goodsInspect(FQCGoodsInspect fqcGoodsInspect) {
                fqcSeaechFragment.onGoodsInspect(fqcGoodsInspect);
                replaceFragmentContent(fqcSeaechFragment, "fqcSeaechFragment");
            }

            @Override
            public void halfGoodsInspect(FQCHalfGoodsInspect fqcHalfGoodsInspect) {
                fqcSeaechFragment.onHalfGoodsInspect(fqcHalfGoodsInspect);
                replaceFragmentContent(fqcSeaechFragment, "fqcSeaechFragment");
            }
        });


        fqcSeaechFragment.setIondataClickback(new FQCSeaechFragment.IondataClickback() {
            @Override
            public void onGoodsField(FQCGoodsField.DataBeanX.DataBean dataBean) {
                fqcFragment = new FQCFragment();
                replaceFragmentContent(fqcFragment, "fqcFragment");
                fqcFragment.onGoodsField(dataBean);
            }

            @Override
            public void onGoodsInspect(int postion) {

            }

            @Override
            public void onHalfGoodsInspect(int postion) {

            }
        });

        sendRCheckFragment.setSendRCheckSearch(new SendRCheckFragment.onSendRCheckSearch() {
            @Override
            public void OnOutFatoryMsg() {
                sendRCKSearchFragment = new SendRCKSearchFragment();
                switchContent(sendRCheckFragment, sendRCKSearchFragment,
                        "sendRCKSearchFragment", 0, 0);
                sendRCKSearchFragment.setRcksCallback(new SendRCKSearchFragment.RCKSCallback() {
                    @Override
                    public void postdata(OutFactoryMsg.DataBeanX.DataBean dataBean) {
                        sendRCheckFragment.getdata(dataBean);
                        TheFragmentChange("sendRCheckFragment", "sendRCKSearchFragment",
                                sendRCheckFragment, sendRCKSearchFragment);
//                        replaceFragmentContent(sendRCheckFragment,"sendRCheckFragment");
//                        switchContent(sendRCKSearchFragment,sendRCheckFragment,"sendRCheckFragment");
                    }
                });
            }
        });

        sendRCheckFragment.setSendRCKClickListener(new SendRCheckFragment.SendRCKClickListener() {
            @Override
            public void postPoduData(SRCPoduMsg.DataBeanX.DataBean dataBean, String tag) {
                srckPoduEditFragment = new SRCKPoduEditFragment();
                srckPoduEditFragment.getdata00(dataBean, tag);
                switchContent(sendRCheckFragment, srckPoduEditFragment,
                        "srckPoduEditFragment", 0, 0);

            }

            @Override
            public void postPlanData(SRCKPlanMsg.DataBeanX.DataBean dataBean, String tag) {
                srckPoduEditFragment = new SRCKPoduEditFragment();
                srckPoduEditFragment.getdata01(dataBean, tag);
                switchContent(sendRCheckFragment, srckPoduEditFragment,
                        "srckPoduEditFragment", 0, 0);
            }
        });
    }


    private void addFragmentContent(Fragment paraFragment, String Tag) {

        localFragmentTransaction.add(R.id.fragment_container, paraFragment, Tag);
        localFragmentTransaction.addToBackStack(null);
        //记录commit一次操作,与mFragmnetManager.popBackStack();匹配使用
        //commitAllowingStateLoss 优于commit方法,当使用commit方法时,系统将进行状态判断
        //，如果状态（mStateSaved ）已经保存，将发生"Can not perform this action after onSaveInstanceState"错误。
        //如果mNoTransactionsBecause已经存在，将发生"Can notperform this action inside of " + mNoTransactionsBecause错误。
        localFragmentTransaction.commitAllowingStateLoss();
    }

    private void replaceFragmentContent(Fragment paraFragment, String Tag) {

        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, paraFragment, Tag);
        fragmentTransaction.addToBackStack(null);
        //记录commit一次操作,与mFragmnetManager.popBackStack();匹配使用
        //commitAllowingStateLoss 优于commit方法,当使用commit方法时,系统将进行状态判断
        //，如果状态（mStateSaved ）已经保存，将发生"Can not perform this action after onSaveInstanceState"错误。
        //如果mNoTransactionsBecause已经存在，将发生"Can notperform this action inside of " + mNoTransactionsBecause错误。
        fragmentTransaction.commitAllowingStateLoss();
    }

    /**
     * fragment 切换
     *
     * @param from
     * @param to
     * @param queryCustom
     */
    public void switchContent(Fragment from, Fragment to, String Tag,
                              Object queryCustom,
                              ArrayList<? extends Parcelable> customConditons,
                              ArrayList<? extends Parcelable> customTypes,
                              ArrayList<? extends Parcelable> moneyTypes,
                              ArrayList<? extends Parcelable> copayTypes, int Position
    ) {
        if (!to.isAdded()) { // 先判断是否被add过
            Bundle args = new Bundle();
            args.putParcelable("queryCustom", (Parcelable) queryCustom);
            args.putInt("Position", Position);
            args.putParcelableArrayList("customConditons", customConditons);
            args.putParcelableArrayList("customTypes", customTypes);
            args.putParcelableArrayList("moneyTypes", moneyTypes);
            args.putParcelableArrayList("copayTypes", copayTypes);
            to.setArguments(args);
            localFragmentTransaction = this.mFragmentManager.beginTransaction();
            localFragmentTransaction.hide(from).add(R.id.fragment_container, to, Tag);

            localFragmentTransaction.addToBackStack(null);
            localFragmentTransaction.commit();
        } else {
            localFragmentTransaction.hide(from).show(to).commit(); // 隐藏当前的fragment，显示下一个
            localFragmentTransaction.commitAllowingStateLoss();
        }
    }


    public void switchContent(Fragment from, Fragment to, String Tag,
                              int mark, int position
    ) {
        if (!to.isAdded()) { // 先判断是否被add过
            Bundle args = new Bundle();
            args.putInt("position", position);
            args.putInt("mark", mark);
            to.setArguments(args);
            localFragmentTransaction = this.mFragmentManager.beginTransaction();
            localFragmentTransaction.hide(from).add(R.id.fragment_container, to, Tag);
            localFragmentTransaction.addToBackStack(null);
            localFragmentTransaction.commit();
        } else {

            localFragmentTransaction.hide(from).show(to).commit(); // 隐藏当前的fragment，显示下一个
            localFragmentTransaction.addToBackStack(null);
            localFragmentTransaction.commitAllowingStateLoss();
        }
    }

    public void switchContent(Fragment from, Fragment to, String Tag
    ) {
        if (!to.isAdded()) { // 先判断是否被add过
//            Bundle args = new Bundle();
//            args.putInt("position", position);
//            args.putInt("mark", mark);
//            to.setArguments(args);
            localFragmentTransaction = this.mFragmentManager.beginTransaction();
            localFragmentTransaction.hide(from).add(R.id.fragment_container, to, Tag);
            localFragmentTransaction.addToBackStack(null);
            localFragmentTransaction.commit();
        } else {
            FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
            fragmentTransaction.hide(from).show(to).commit(); // 隐藏当前的fragment，显示下一个
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commitAllowingStateLoss();
        }
    }


    public interface SearchFragmentButton {
        void searchFramentButtonClick(PbProductInfo.DataEntity data, String info);

        void searchPackTypeInfoClick(PackTypeInfo.DataEntity dataEntity, String info);

        void searchCustomInfoClick(SomeCustomInfo.DataEntity dataEntity);

        void searchComtomTypeInfoClick(CustomType.DataBean customType, int type);


    }

    public void searchFragmentClickEvent(SearchFragmentButton searchFragmentButton) {

        this.searchFragmentButton = searchFragmentButton;
    }

    public interface SearchNewFragmentButton {
        void searchNewFramentButtonClick(PbProductInfo.DataEntity data, String info);

        void searchNewPackTypeInfoClick(PackTypeInfo.DataEntity dataEntity, String info);

        void searchNewCustomInfoClick(SomeCustomInfo.DataEntity dataEntity);

        void searchNewComtomTypeInfoClick(CustomType.DataBean customType, int type);


    }

    public void searchNewFragmentClickEvent(SearchNewFragmentButton searchNewFragmentButton) {

        this.searchNewFragmentButton = searchNewFragmentButton;
    }


    /**
     * 初始化日历时间
     */
    private void initCalendar() {
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        monthOfYear = calendar.get(Calendar.MONTH);
        dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        currentMilli = calendar.getTimeInMillis();
        Time time = new Time("GMT+8");
        time.setToNow();

        syear = time.year;
        smonthOfYear = time.month;
        sdayOfMonth = time.monthDay;
    }

    public void selectCalendar(View view) {

        DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                                  int dayOfMonth) {
                EditText editText = (EditText) findViewById(R.id.ed_4);

                startMilli = changeMilli(year, monthOfYear, dayOfMonth);
//                Log.d(TAG, "onDateSet:"+startMilli+"....."+currentMilli);
                if (startMilli > currentMilli) {
                    ToastUtil.showToast(DetailedActivity.this, "选择日期不能大于今日");
                    year = syear;
                    monthOfYear = smonthOfYear;
                    dayOfMonth = sdayOfMonth;
                    startMilli = currentMilli;
                }

                editText.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);

            }

        }, year, monthOfYear, dayOfMonth);

        datePickerDialog.show();

    }

    private long changeMilli(int year, int month, int day) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-dd", Locale.ENGLISH);
        String str = year + "-" + (month + 1) + "-" + day;
        long millionSeconds = 0;//毫秒
        try {
            millionSeconds = sdf.parse(str).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }

//        Log.d("今天", millionSeconds + "");
        return millionSeconds;
    }

    public void selectEndCalendar(View view) {

        DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                                  int dayOfMonth) {
//                Log.d("da",year+""+monthOfYear+dayOfMonth);
                EditText editText = (EditText) findViewById(R.id.ed_3);
                endMilli = changeMilli(year, monthOfYear, dayOfMonth);
//                Log.d(TAG, "onDateSet:"+startMilli+"....."+currentMilli);

                if (endMilli > currentMilli) {
                    ToastUtil.showToast(DetailedActivity.this, "选择日期不能大于今日");
                    year = syear;
                    monthOfYear = smonthOfYear;
                    dayOfMonth = sdayOfMonth;
                }

                editText.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }

        }, year, monthOfYear, dayOfMonth);

        datePickerDialog.show();
//        Log.d("i","qqqq");
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:// 点击返回图标事件
//                if (newBuildFragment != null) {
//                    TheFragmentChange("editCustomInfoFragment", "newBuildFragment",
//                            editCustomInfoFragment, newBuildFragment);
//                } else if (updateCustomInfoFragment != null) {
//                    Log.d(TAG, "onOptionsItemSelected:  update");
//                    TheFragmentChange("editCustomInfoFragment", "updateCustomInfoFragment",
//                            editCustomInfoFragment, updateCustomInfoFragment);
//                } else if (buildProductInfoFragment != null) {
//                    TheFragmentChange("editProductInfoFragment", "buildProductFragment",
//                            editCustomInfoFragment, updateCustomInfoFragment);
//                } else if (updateProductInfoFragment != null) {
//                    TheFragmentChange("editProductInfoFragment", "updateProductInfoFragment",
//                            editProductInfoFragment, updateProductInfoFragment);
//                } else if (cODetailedFragment != null) {
//                    TheFragmentChange("customOrderApprovalFragment", "cODetailedFragment"
//                            , customOrderApprovalFragment, cODetailedFragment);
//                } else if (pODetailedFragment != null) {
//                    TheFragmentChange("purchaseOrderApprovalFragment", "pODetailedFragment",
//                            purchaseOrderApprovalFragment, pODetailedFragment
//                    );
//                } else {
//
//                    this.finish();
//                }
                if (mFragmentManager.getBackStackEntryCount() > 1) {

                    mFragmentManager.popBackStack();
                } else {
                    this.finish();
                }
            default:
                return super.onOptionsItemSelected(item);
        }
    }

}
